<template>
	<view class="chat">
		<!-- 顶部标题 -->
		<!-- 聊天主体 -->
		<view class="chat-body">
			<!-- 聊天记录 -->
			<!--  -->
			<scroll-view
			id="scrollview"
			ref="scrollView"
			scroll-y="true"
			class="scroll-view "
			>
				<view class="official-content" id="msglistview ">
					<view v-for="(item, index) in msgList" :key="index">
						<!-- 时间提示 -->
						<view class="font text-center pt-1" v-if="item.payload">{{
							item.payload.text
						}}</view>
						<!-- 自己发的消息 -->
						<view class="item self" v-if="item.userContent != '' && item.userContent != undefined">
							<!-- 文字内容 -->
							<view class="content right">
								{{ item.userContent }}
							</view>
							<!-- 头像 -->
							<image class="avatar" :src="userImage"> </image>
						</view>
						<!-- 机器人发的消息 -->
						<view class="item Ai" v-if="item.botContent != '' && item.botContent != undefined">
							<!-- 头像 -->
							<image class="avatar" :src="Domain_ICON + '/serve.png'"> </image>
							<!-- 文字内容 -->
							<view class="content left">
								{{
									item.botContent
								}}
							</view>
						</view>
			  		</view>
				</view>
			</scroll-view>
		</view>
		<!-- 底部消息发送栏 -->
		<!-- 用来占位，防止聊天消息被发送框遮挡 -->
	</view>
</template>
<script>
	const app = getApp();
	import {
		msgTimeFormat
	} from "@/static/js/common.js";
	import {WXMemberServes} from "@/api/WeChat.js";
	export default {
		data() {
			return {
				userImage: app.globalData.memberInfo.Image,
				serveImage: app.globalData.memberInfo.Image,
				msgList: [
				],
				Domain_ICON: app.globalData.Domain_ICON, //全局变量域名
			};
		},
		onLoad() {
			this.History();
		},
		methods: {
			//历史记录  this.msgList = msgTimeFormat(this.msgList, 0, 1);
			async History(){
				const res = await WXMemberServes({
					User_Type: "custom",
                    userid:app.globalData.openid,
                    Enterprise_Info_SerialNumber: app.globalData.enterprise,
				})
				console.log(res);
				this.msgList = msgTimeFormat(res.Data, 0, 1);
			}
		},
	};
</script>
<style lang="scss" scoped>
	$chatContentbgc: #c2dcff;
	$sendBtnbgc: #4f7df5;

	view,
	button,
	text,
	input,
	textarea {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}

	.scroll-Y {
		height: 300rpx;
	}

	/* 聊天消息 */
	.chat {
		background-color: #f6f6f6;
		.topTabbar {
			width: 100%;
			height: 90rpx;
			line-height: 90rpx;
			display: flex;
			margin-top: 80rpx;
			justify-content: space-between;

			.icon {
				margin-left: 20rpx;
			}

			.text {
				margin: auto;
				font-size: 16px;
				font-weight: 700;
			}

			.button {
				width: 10%;
				margin: auto 20rpx auto 0rpx;
			}
		}

		.scroll-view {
			padding: 0 0 170rpx 0;

			::-webkit-scrollbar {
				display: none;
				width: 0 !important;
				height: 0 !important;
				-webkit-appearance: none;
				background: transparent;
				color: transparent;
			}

			// background-color: orange;

		}

		.chat-body {
			display: flex;
			flex-direction: column;
			padding-top: 23rpx;
			// background-color:skyblue;

			.self {
				justify-content: flex-end;
			}

			.item {
				display: flex;
				padding: 23rpx 30rpx;
				// background-color: greenyellow;

				.right {
					background-color: $chatContentbgc;
				}

				.left {
					background-color: #ffffff;
				}

				// 聊天消息的三角形
				.right::after {
					position: absolute;
					display: inline-block;
					content: "";
					width: 0;
					height: 0;
					left: 100%;
					top: 10px;
					border: 12rpx solid transparent;
					border-left: 12rpx solid $chatContentbgc;
				}

				.left::after {
					position: absolute;
					display: inline-block;
					content: "";
					width: 0;
					height: 0;
					top: 10px;
					right: 100%;
					border: 12rpx solid transparent;
					border-right: 12rpx solid #ffffff;
				}

				.content {
					position: relative;
					max-width: 486rpx;
					border-radius: 8rpx;
					word-wrap: break-word;
					padding: 24rpx 24rpx;
					margin: 0 24rpx;
					border-radius: 5px;
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 42rpx;
				}

				.avatar {
					display: flex;
					justify-content: center;
					width: 78rpx;
					height: 78rpx;
					border-radius: 50rpx;
					overflow: hidden;

					image {
						align-self: center;
					}
				}
			}
		}

		/* 底部聊天发送栏 */
		.chat-bottom {
			width: 100%;
			height: 100rpx;
			background: #f4f5f7;
			transition: all 0.1s ease;

			.send-msg {
				display: flex;
				align-items: flex-end;
				padding: 16rpx 30rpx;
				width: 100%;
				min-height: 177rpx;
				position: fixed;
				bottom: 0;
				background: #fff;
				transition: all 0.1s ease;
			}

			.uni-textarea {
				width: 537rpx;
				max-height: 500rpx;
				background: #f1f1f1;
				border-radius: 40rpx;
				font-size: 32rpx;
				font-family: PingFang SC;
				color: #333333;
				line-height: 74rpx;
				text-indent: 30rpx;

				//   margin: 0 0 20rpx 0;
				/deep/ .uni-easyinput__content-textarea {
					min-height: 60rpx;
					display: flex;
					align-items: center;
					padding: 0;
				}

				/dee/ .input-padding {
					padding: 0;
				}
			}

			.send-btn {
				display: flex;
				align-items: center;
				justify-content: center;
				//   margin-bottom: 70rpx;
				margin-left: 25rpx;
				width: 120rpx;
				height: 84rpx;
				background: #ed5a65;
				//   border-radius: 50rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #ffffff;
				line-height: 28rpx;
			}
		}
	}
</style>